<template>
	<view>
		<!-- 状态栏 -->

		<!-- 占位 -->

		<view class="category-list">
			<!-- 左侧分类导航 -->
			<scroll-view scroll-y="true" class="left">
				<view class="row" v-for="(category,index) in categoryList" :key="category.id"
					:class="[index==showCategoryIndex?'on':'']" @tap="showCategory(index,category.id)">
					<view class="text">
						<view class="block"></view>
						{{category.name}}
					</view>
				</view>

			</scroll-view>
			<!-- 右侧子导航 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category">
					<!-- <view class="banner">
						<image :src="category.banner"></image>
					</view> -->
					<view class="list">
						<view class="box" v-for="(box,i) in sonList" :key="i" @tap="toCategory(box)">
							<image mode="" :src="box.img_url | getImg"></image>
							<view class="text">{{box.name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import {
		ClassList,
		ClassSon
	} from "@/api/api.js"
	//高德SDK
	import amap from '@/common/SDK/amap-wx.js';
	export default {
		data() {
			return {
				showCategoryIndex: 0,
				headerPosition: "fixed",
				city: "北京",
				//分类列表
				categoryList: [],
				sonList: []
			}
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		onLoad() {
			this.ClassList()
			this.amapPlugin = new amap.AMapWX({
				//高德地图KEY，随时失效，请务必替换为自己的KEY，参考：http://ask.dcloud.net.cn/article/35070
				key: '7c235a9ac4e25e482614c6b8eac6fd8e'
			});
			//定位地址
			// this.amapPlugin.getRegeo({
			// 	success: (data) => {
			// 		this.city = data[0].regeocodeData.addressComponent.city.replace(/市/g, ''); //把"市"去掉
			// 	}
			// });
		},
		methods: {
			ClassList() {
				ClassList().then(res => {
					this.categoryList = res.data
					if (this.categoryList.length > 0) {
						console.log();
						this.ClassSon(this.categoryList[0].id)
					}
				})
			},
			//消息列表
			toMsg() {
				uni.navigateTo({
					url: '../../msg/msg'
				})
			},
			//分类切换显示
			showCategory(index, id) {
				this.showCategoryIndex = index;
				this.ClassSon(id)
			},
			ClassSon(index) {
				ClassSon({
					class_id: index
				}).then(res => {
					console.log(res);
					this.sonList = res.data
				})
			},
			toCategory(e) {
				uni.setStorageSync('catName', e.name);
				uni.navigateTo({
					url: '../../goods/goods-list/goods-list?sid=' + e.id + '&name=' + e.name
				});
			},
			//搜索跳转
			toSearch() {
				uni.showToast({
					title: "建议跳转到新页面做搜索功能"
				});
			}
		}
	}
</script>
<style lang="scss">
	.category-list {
		width: 100%;
		background-color: #0f172a;
		display: flex;

		.left,
		.right {
			position: absolute;

			top: 0upx;
			/*  #ifdef  APP-PLUS  */
			top: calc(0upx + var(--status-bar-height));
			/*  #endif  */
			bottom: 0upx;
		}

		.left {
			width: 24%;
			left: 0upx;
			background-color: #0f172a;
			color: #fff;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;

				.text {
					width: 100%;
					position: relative;
					font-size: 28upx;
					display: flex;
					justify-content: center;
					color: #f2f2f2;

					.block {
						position: absolute;
						width: 0upx;
						left: 0;
					}
				}

				&.on {
					height: 100upx;
					background-color: #303C5A;

					.text {
						font-size: 30upx;
						font-weight: 600;
						color: #798AD6;
						padding: 0 15px;
						box-sizing: border-box;

						.block {
							width: 10upx;
							height: 80%;
							top: 10%;
							background-color: #7989D5;
						}
					}
				}
			}
		}

		.right {
			width: 76%;
			left: 24%;
			background-color: #1e293b;

			.category {
				width: 94%;
				padding: 20upx 3%;

				.banner {
					width: 100%;
					height: 24.262vw;
					border-radius: 10upx;
					overflow: hidden;
					box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);

					image {
						width: 100%;
						height: 24.262vw;
					}
				}

				.list {
					margin-top: 40upx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.box {
						width: calc(71.44vw / 3);
						margin-bottom: 30upx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 60%;
							height: calc(71.44vw / 3 * 0.6);
						}

						.text {
							margin-top: 5upx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
							color: #fff;
						}
					}
				}
			}
		}
	}
</style>